from openai import OpenAI
import logging as log

log.basicConfig(level=log.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')


class OneApi(object):
    def __init__(self, base_url, api_key):
        self.base_url = base_url
        self.api_key = api_key
        self.openai = OpenAI(base_url=base_url, api_key=self.api_key)

    def chat(self, message, model):
        chat_completion = self.openai.chat.completions.create(
            messages=[
                {
                    "role": "user",
                    "content": message,
                }
            ],
            model=model,
        )
        return chat_completion

    def chatMsg(self, message, model):
        return self.chat(message, model).choices[0].message.content.strip()
